function(embed_headers output_h output_cpp)
  set(prologue "#include <string_view>\n\nnamespace bpftrace {\n")
  get_filename_component(output_h_name ${output_h} NAME)
  file(WRITE ${output_h} ${prologue})
  file(WRITE ${output_cpp} "#include \"${output_h_name}\"\n\n")
  file(APPEND ${output_cpp} ${prologue})

  file(GLOB headers *.h)
  foreach(header ${headers})
    set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${header})
    get_filename_component(filename ${header} NAME)
    string(MAKE_C_IDENTIFIER ${filename} varname)
    file(READ ${header} contents)
    file(APPEND ${output_h} "extern const std::string_view ${varname};\n")
    file(APPEND ${output_cpp} "const std::string_view ${varname} = R\"CONTENTS(${contents})CONTENTS\";\n\n")
  endforeach()

  set(epilogue "} // namespace bpftrace")
  file(APPEND ${output_h} ${epilogue})
  file(APPEND ${output_cpp} ${epilogue})
endfunction()

embed_headers(${CMAKE_CURRENT_BINARY_DIR}/headers.h ${CMAKE_CURRENT_BINARY_DIR}/headers.cpp)
add_library(resources STATIC ${CMAKE_CURRENT_BINARY_DIR}/headers.cpp)
